<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增
                </el-button>
            </el-col>
            <!-- <el-col :span="1.5">
                <el-switch v-model="form.shoutdown" active-color="#31343a" inactive-color="#c71515">
                </el-switch>
            </el-col> -->
        </el-row>
        <el-table class="box_table" :data="tableData" :max-height="maxHeight" style="width: 100%">
            <el-table-column label="id" prop="ID" width="40" align="center">
            </el-table-column>
            <el-table-column label="直播事件" prop="event" width="130" align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="事件内容" align="center" prop="eventmsg" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="funcname" label="触发功能" align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="runnum" width="100" label="执行次数" align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改
                    </el-button>
                    <!-- <el-button type="text" @click="handleTest(scope.row)" icon="el-icon-video-play"> 测试</el-button> -->
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <opt ref="opt" @getList="getList"></opt>
        <test ref="test"></test>
    </div>
</template>

<script>

import opt from './opt.vue'
import test from '@/components/testDialog.vue'
import { GetIndexList, IndexDel } from '../../../../wailsjs/go/main/App'

export default {
    name: 'MyYongjieStreaming',
    components: { opt, test },

    data() {
        return {
            maxHeight: 0,
            tableData: [
            ]
        };
    },
    created() {
        this.maxHeight = (window.innerHeight - 85) + 'px'
    },
    mounted() {
        this.getList();
    },
    methods: {
        // 获取列表
        getList() {
            GetIndexList().then(res => {
                this.tableData = JSON.parse(res);
            })
        },
        handleAdd() {
            this.$refs.opt.handleAdd();
        },
        handleUpdate(row) {
            this.$refs.opt.handleUpdate(row);
        },
        handleTest(row) {
            this.$refs.test.handleTest(row);
        },
        // 删除
        handleDelete(row) {
            let _this = this;
            this.$confirm('是否确认删除该条数据', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                IndexDel(row.ID).then(res => {
                    if (res == '1') {
                        _this.getList()
                    }
                })
            }).catch(function () {
            });
        },

    },
};
</script>

<style lang="less" scoped>
.mb8 {
    margin-bottom: 15px;
}
</style>